﻿package morn.core.managers
{
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;

    public class ImageS9BitmapData extends Object
    {
        public static var clipRect:Rectangle = new Rectangle();
        public static var grid:Rectangle = new Rectangle();
        private static var _cache:Dictionary = new Dictionary();
        private static var newRect:Rectangle = new Rectangle();
        public static var UrlToSizeGrid:Object;

        public function ImageS9BitmapData()
        {
            return;
        }// end function

        public static function getS9Bitmaps(param1:BitmapData, param2:Array, param3:Number, param4:Number, param5:Boolean = true, param6:String = null) : Array
        {
            var _loc_7:Array = null;
            var _loc_8:Array = null;
            var _loc_9:Array = null;
            var _loc_10:int = 0;
            var _loc_11:int = 0;
            var _loc_12:BitmapData = null;
            if (_cache[param1])
            {
                return _cache[param1];
            }
            setRect(grid, param2[0], param2[1], param1.width - param2[0] - param2[2], param1.height - param2[1] - param2[3]);
            _loc_7 = [0, grid.top, grid.bottom, param1.height];
            _loc_8 = [0, grid.left, grid.right, param1.width];
            _loc_9 = new Array();
            _loc_10 = 0;
            _loc_11 = 0;
            _loc_11 = 0;
            while (_loc_11 < 3)
            {
                
                _loc_10 = 0;
                while (_loc_10 < 3)
                {
                    
                    setRect(clipRect, _loc_8[_loc_10], _loc_7[_loc_11], _loc_8[(_loc_10 + 1)] - _loc_8[_loc_10], _loc_7[(_loc_11 + 1)] - _loc_7[_loc_11]);
                    if (clipRect.width > 0 && clipRect.height > 0)
                    {
                        _loc_12 = new BitmapData(clipRect.width, clipRect.height, true, 0);
                        _loc_12.copyPixels(param1, clipRect, new Point(0, 0));
                        _loc_9[_loc_11 * 3 + _loc_10] = _loc_12;
                        ;
                    }
                    _loc_10++;
                }
                _loc_11++;
            }
            _cache[param1] = _loc_9;
            if (UrlToSizeGrid && !UrlToSizeGrid[param6])
            {
                UrlToSizeGrid[param6] = param2;
            }
            return _loc_9;
        }// end function

        public static function setRect(param1:Rectangle, param2:Number = 0, param3:Number = 0, param4:Number = 0, param5:Number = 0) : Rectangle
        {
            param1.x = param2;
            param1.y = param3;
            param1.width = param4;
            param1.height = param5;
            return param1;
        }// end function

    }
}
